{extend name="main/index" /}
{block name="main"}
{js href="/static/admin/assets/js/jquery.min.js"}
{js href="/static/admin/assets/js/toastr.min.js"}
<script>
    $(function () {
        // 触发删除用户
        $('.del-btn').click(function () {
            var uc_id = $(this).attr('data-id');
            console.log(uc_id);
            if (confirm('您确定要[ 删除 ]该用户吗?')) {
                var obj = $(this).parents('tr');
                console.log(obj);
                delAjax(uc_id,obj);
            }


        });


    });

     // 执行AJAX删除
    function delAjax(id, obj) {
        $.ajax({
            type: 'get',
            url: '/user/delete',
            data: {id:id},
            dataType: 'json',
            success: function (data) {
                console.log(data);
                if (data.status) {
                    toastr.success(data.info);
                    // 移除tr节点
                    obj.remove();
                } else {
                    toastr.error(data.info, 'FBI WARNING: ')
                }

            },
            error: function () {
                alert('AJAX 执行失败!');
            }
        });
    }


</script>

<script>
    // alert('123');
</script>
<!-- Start right content -->
<div class="content-page">
    <!-- ============================================================== -->
    <!-- Start Content here -->
    <!-- ============================================================== -->
    <div class="content">
        <!-- Page Heading Start -->
        <div class="page-heading">
            <h1><i class='fa fa-table'></i> Tables</h1>
            <h3>Basic & Simple Sortable Tables</h3></div>
        <!-- Page Heading End-->                <!-- Your awesome content goes here -->
  

        <div class="row">
            <div class="col-md-12">
                <div class="widget">
                    <div class="widget-header transparent">
                        <h2><strong>Toolbar</strong> CRUD Table</h2>
                        <div class="additional-btn">
                            <a href="#" class="hidden reload"><i class="icon-ccw-1"></i></a>
                            <a href="#" class="widget-toggle"><i class="icon-down-open-2"></i></a>
                            <a href="#" class="widget-close"><i class="icon-cancel-3"></i></a>
                        </div>
                    </div>
                    <div class="widget-content">
                        <div class="data-table-toolbar">
                            <div class="row">
                                <form action="{:url('admin/user/index')}">
                                <div class="col-md-4">
                                        <input type="text" name="uname" class="form-control" placeholder="用户名...">
                                </div>
                                <div class="col-md-2">
                                    <button class="btn btn-primary">search</button>
                                </div>
                                </form>
                                <div class="col-md-6">
                                    <div class="toolbar-btn-action">
                                        <a class="btn btn-success"><i class="fa fa-plus-circle"></i> Add new</a>
                                        <a class="btn btn-danger"><i class="fa fa-trash-o"></i> Delete</a>
                                        <a class="btn btn-primary"><i class="fa fa-refresh"></i> Update</a>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="table-responsive">
                            <table data-sortable class="table table-hover table-striped">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>用户名</th>
                                    <th>真实姓名</th>
                                    <th>所属角色</th>
                                    <th>操作</th>
                                </tr>
                                </thead>

                                <tbody>
                                {foreach $list as $v}
                                <tr>
                                    <td>{$v.id}</td>
                                    <td><strong>{$v.username}</strong></td>
                                    <td>{$v.name}</td>
                                    <td>
                                        {foreach $v.role as $vo}
                                        <span style="color:#999">{$vo}</span>
                                        &nbsp;
                                        {/foreach}
                                    </td>
                                    <td>
                                    <a href="{:url('admin/user/delete', ['id'=>$v['id']])}">删除</a>
                                    <a href="{:url('admin/user/edit', ['id'=>$v['id']])}">修改</a>
                                    <a href="{:url('admin/user/rolelist', ['id'=>$v['id']])}">分配角色</a>

                                    </td>
                                </tr>

                                {/foreach}
                                

                                </tbody>
                            </table>
                        </div>
                        {$page}
                        <!--<div class="data-table-toolbar">-->
                            <!--<ul class="pagination">-->
                                <!--<li class="disabled"><a href="#">&laquo;</a></li>-->
                                <!--<li class="active"><a href="#">1</a></li>-->
                                <!--<li><a href="#">2</a></li>-->
                                <!--<li><a href="#">3</a></li>-->
                                <!--<li><a href="#">4</a></li>-->
                                <!--<li><a href="#">5</a></li>-->
                                <!--<li><a href="#">&raquo;</a></li>-->
                            <!--</ul>-->
                        <!--</div>-->
                    </div>
                </div>
            </div>

        </div>

        <!-- Footer Start -->
        <footer>
            Huban Creative &copy; 2014
            <div class="footer-links pull-right">
                <a href="#">About</a><a href="#">Support</a><a href="#">Terms of Service</a><a href="#">Legal</a><a
                    href="#">Help</a><a href="#">Contact Us</a>
            </div>
        </footer>
        <!-- Footer End -->
    </div>
    <!-- ============================================================== -->
    <!-- End content here -->
    <!-- ============================================================== -->

</div>
<!-- End right content -->

{/block}

